import http from '../../../common/httpUtil';
import * as types from './invitationMutationTypes';

const actions = {


  queryInvite({commit}, {pageIndex = 1, pageSize = 10} = {}) {
    commit(types.SYS_FILE_UPLOAD_QUERY_FILES_BEGIN);

    return http.getRaw(`user/all?pageIndex=${pageIndex}&pageSize=${pageSize}`)
      .then(res => {
        console.log(res)
        let files = res.body.result;
        for (var i = 0; i < files.length; i++) {
          let timedata = new Date(parseInt(files[i].createDate)).toLocaleDateString()
          files[i].createDate = timedata
        }
        console.log(files)
        commit(types.SYS_FILE_UPLOAD_QUERY_FILES_SUC, {files});
      });
  },

  searchInvite({commit}, {userfrom, userName, phoneNumber, inviperson, inviphoneNumber, pageIndex = 1, pageSize = 10} = {}) {
    commit(types.SYS_FILE_UPLOAD_QUERY_FILES_BEGIN);

    return http.getRaw(`user/all?pageIndex=${pageIndex}&pageSize=${pageSize}&userFrom=${userfrom}&userName=${userName}&userMobile=${phoneNumber}&userInviterName=${inviperson}&userInviterMobile=${inviphoneNumber}`).then(res => {
      let files = res.body.result;
      for (var i = 0; i < files.length; i++) {
        let timedata = new Date(parseInt(files[i].createDate)).toLocaleDateString()
        files[i].createDate = timedata
      }
      console.log(files)
      commit(types.SYS_FILE_UPLOAD_QUERY_FILES_SUC, {files});
    })
  },


  queryInviteCount({commit}, {pageIndex = 1, pageSize = 10} = {}) {
    commit(types.SYS_FILE_UPLOAD_QUERY_FILES_COUNT_BEGIN);
    return http.getRaw(`user/count`)
      .then(res => {
        console.log(res)
        let totalCount = res.body.result;
        commit(types.SYS_FILE_UPLOAD_QUERY_FILES_COUNT_SUC, {totalCount})
      });
  },

  searchInviteCount({commit}, {userfrom, userName, phoneNumber, inviperson, inviphoneNumber} = {}) {
    commit(types.SYS_FILE_UPLOAD_QUERY_FILES_COUNT_BEGIN);

    return http.getRaw(`user/count?userFrom=${userfrom}&userName=${userName}&userMobile=${phoneNumber}&userInviterName=${inviperson}&userInviterMobile=${inviphoneNumber}`).then(res => {
      let totalCount = res.body.result;
      commit(types.SYS_FILE_UPLOAD_QUERY_FILES_COUNT_SUC, {totalCount})
    })
  }

  // editFile({commit}, {id, description} = {}) {
  //   return http.post(`sys/organ/save_file?id=${id}&description=${description}`).then(res => {
  //     console.log(res)
  //   })
  // },

  // searchPicturelist({commit}, {id, callback} = {}) {
  //   commit(types.SYS_FILE_UPLOAD_QUERY_PICTURE_LIST_BEGIN);
  //
  //   return http.post(`sys/organ/get_organ_files?userId=${id}`).then(res => {
  //     if (res) {
  //       console.log(res)
  //       let pictures = res;
  //       commit(types.SYS_FILE_UPLOAD_QUERY_PICTURE_LIST_SUC, {pictures})
  //     }
  //     callback()
  //   })
  //
  //
  // }

};


export default actions;
